package com.example.servicea.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.SqlHelper;
import com.baomidou.mybatisplus.plugins.Page;
import com.example.servicea.dao.UserRoleMapper;
import com.example.servicea.entity.UserRoleEntity;
import com.example.servicea.service.UserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * @Author generator.
 * @Date: 2017/10/26 10:58
 */
@Service("userRoleServiceImpl")
public class UserRoleServiceImpl implements UserRoleService {
	@Autowired
	private UserRoleMapper userRoleMapper;
    @Override
    public boolean insert(UserRoleEntity obj){
        return SqlHelper.retBool(userRoleMapper.insert(obj));
    }
    @Override
    public List<UserRoleEntity> selectList(UserRoleEntity userRole){
        EntityWrapper<UserRoleEntity> query = new EntityWrapper<UserRoleEntity>();
		return userRoleMapper.selectList(query);
	}

    @Override
    public Page selectPage(UserRoleEntity userRole, String page, String limit){
        EntityWrapper<UserRoleEntity> query = new EntityWrapper<UserRoleEntity>();
        List<UserRoleEntity> list = userRoleMapper.selectPage(
                new Page<UserRoleEntity>(Integer.parseInt(page),Integer.parseInt(limit)),
                query);
        int total = userRoleMapper.selectCount(query);
        Page UserRoleEntityPage = new Page();
        return UserRoleEntityPage;
	}
    @Override
    public int selectCount(UserRoleEntity userRole){
        EntityWrapper<UserRoleEntity> query = new EntityWrapper<UserRoleEntity>();
        return userRoleMapper.selectCount(query);
	}

    @Override
    public UserRoleEntity selectOne(UserRoleEntity userRole){
        return userRoleMapper.selectOne(new UserRoleEntity());
	}

    @Override
    public UserRoleEntity selectById(String id){
        return userRoleMapper.selectById(id);
	}

	@Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateById(UserRoleEntity userRole){
        return SqlHelper.retBool(userRoleMapper.updateById(userRole));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteById(String id){
        return SqlHelper.retBool(userRoleMapper.deleteById(Integer.parseInt(id)));
	}

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBatchIds(String ids){
        String[] s = ids.split(",");
        List<String> list = Arrays.asList(s);
        return SqlHelper.retBool(userRoleMapper.deleteBatchIds(list));
	}
	
}
